{% extends 'admin-v2/layout.html.twig' %}
{% import 'admin-v2/macro.html.twig' as admin_macro %}

{% set menu = 'admin_v2_learn_statistics' %}

{% set script_controller = 'user/user-learn-statistics' %}

{% block main %}
    <form id="user-search" class="form-inline well well-sm" action="" method="get" novalidate="">
      <div class="form-group ">
        <input class="form-control" type="text" id="startDate" name="startDate" value="{{ app.request.query.get('startDate') }}" data-min-time="{{ recordEndTime }}" placeholder="{{ 'user.learn.statistics.start_time'|trans }}"  autocomplete="off">
        -
        <input class="form-control" type="text" id="endDate" name="endDate" value="{{ app.request.query.get('endDate') }}" placeholder="{{ 'user.learn.statistics.end_time'|trans }}" autocomplete="off">
        <div class="form-group">
          <select id="keywordType" name="keywordType" class="form-control">
            {{ select_options(dict('userStatisticsTypes'), app.request.query.get('keywordType') ? app.request.query.get('keywordType') : 'nickname') }}
          </select>
        </div>
        <div class="form-group">
          <input type="text" id="keyword" name="keyword" class="form-control" value="{{ app.request.query.get('keyword') }}"
                 placeholder="{{ 'admin.user.form.input_placeholder.keyword'|trans }}">
        </div>
        <input type="hidden" name="isDefault" value="{{ isDefault|default(false) }}">
      </div>
      <a class="btn btn-primary" id="search">{{'user.learn.statistics.search'|trans}}</a>
      {% include 'export/export-btn.html.twig' with
      {
        'exportFileName': 'user-learn-statistics',
        'targetFormId': 'user-search',
      }
      %}
      <div class="btn-group">
        <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
          <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li class="mbs">
            {% include 'export/export-btn.html.twig' with
              {
                'exportFileName': 'user-learn-statistics',
                'targetFormId': 'user-search',
                'exportClass': 'mbs text-left',
                'text': 'user.learn.statistics.learn_statistics.export'|trans
              }
            %}
          </li>
          <li class="mbs">
            {% include 'export/export-btn.html.twig' with
              {
                'exportFileName': 'user-course-statistics',
                'targetFormId': 'user-search',
                'exportClass': 'mbs text-left',
                'text': 'user.learn.statistics.course_statistics.export'|trans
              }
            %}
          </li>
          <li class="mbs">
            {% include 'export/export-btn.html.twig' with
              {
                'exportFileName': 'user-lesson-statistics',
                'targetFormId': 'user-search',
                'exportClass': 'mbs text-left',
                'text': 'user.learn.statistics.lesson_statistics.export'|trans
              }
            %}
          </li>
          <li class="mbs">
            {% include 'export/export-btn.html.twig' with
              {
                'exportFileName': 'user-learn-statistics',
                'targetFormId': 'user-search',
                'exportClass': 'mbs text-left',
                'fileNames': ['user-course-statistics', 'user-lesson-statistics', 'user-learn-statistics'],
                'text': 'user.learn.statistics.all.export'|trans
              }
            %}
          </li>
          <li>
            <span class="help-block fss text-center">{{ 'user.learn.statistics.export.tips'|trans }}</span>
          </li>
        </ul>
      </div>
      {% include 'admin-v2/widget/tooltip-widget.html.twig' with { icon: 'glyphicon-question-sign', content: 'user.learn.statistics.manage.describe_tips'|trans|raw, placement: 'left'} %}
    </form>
    <table id="user-table" class="table table-striped table-hover" data-search-form="#user-search-form">
      <thead>
        <tr>
          <th>{{'user.learn.statistics.nickname'|trans}}</th>
          <th>{{'user.fields.mobile_simple_label'|trans}}</th>
          <th>{{'user.learn.statistics.join.classroom.num'|trans}}</th>
          <th>{{'user.learn.statistics.exit.classroom.num'|trans}}</th>
          <th>{{'user.learn.statistics.join.course.num'|trans}}</th>
          <th>{{'user.learn.statistics.exit.course.num'|trans}}</th>
          <th>{{'user.learn.statistics.finished.task.num'|trans}}</th>
          <th>{{'user.learn.statistics.video_playing.seconds'|trans}}</th>
          <th>{{'user.learn.statistics.actual.amount'|trans}}</th>
          <th>{{ 'operation'|trans }}</th>
        </tr>
      </thead>
      <tbody>
      {% if isInit %}
          {% for user in users|default() %}
            {% set statistic = statistics[user.id]|default(null) %}
              <tr>
              <td>
                {% if has_permission('admin_v2_user_manage') %}
                  <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_v2_user_show', {id:user.id}) }}">{{ user.nickname|default('--') }}</a>
                {% else %}
                  <span><a target="_blank" href="{{ path('user_show', {id: user.id}) }}">
                  {{ user.nickname }}</a></span>
                {% endif %}
              </td>
              <td>
                {{ user.verifiedMobile|default('--') }}
              </td>
              <td>{{ statistic.joinedClassroomNum|default(0) }}</td>
              <td>{{ statistic.exitClassroomNum|default(0) }}</td>
              <td>{{ statistic.joinedCourseNum|default(0) }}</td>
              <td>{{ statistic.exitCourseNum|default(0) }}</td>
              <td>{{ statistic.finishedTaskNum|default(0) }}</td>
              <td>{{ (userLearnRecords[user.id].userSumTime|default(0)/60)|number_format(1) }}</td>
              <td>{{ statistic.actualAmount|default(0)|to_cash(0) }}</td>
              <td><a href="{{ path('admin_v2_user_learn_detail', {userId:user.id}) }}">{{ 'site.btn.detail'|trans }}</a></td>
            </tr>
          {% endfor %}
          {% if users is empty %}
            <tr><td colspan="20"><div class="empty">{{'user.learn.statistics.empty'|trans}}</div></td></tr>
          {% endif %}  
      {% else %}
        <tr><td colspan="20"><div class="empty">{{'user.learn.statistics.init'|trans}}</div></td></tr>
      {% endif %}
      </tbody>
    </table>

    {% if isInit %}
      {{ admin_macro.paginator(paginator) }}
    {% endif %}
{% endblock %}